﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace FCMS.Mvc
{
    public abstract class SiteBaseController : BaseController
    {
        private static object lockObject = new object();
        private static SkinViewEngine currentViewEngine;

        public SiteBaseController()
        {
            if (currentViewEngine == null)
            {
                lock (lockObject)
                {
                    if (currentViewEngine == null)
                    {
                        currentViewEngine = new SkinViewEngine();
                        SkinManager.LoadViewEngine<SkinViewEngine>(currentViewEngine);
                    }
                }
            }
        }

        protected override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            filterContext.Controller.ViewBag.SkinName = currentViewEngine.SkinName;
            filterContext.Controller.ViewBag.SkinPath = string.Format("/skins/{0}", currentViewEngine.SkinName);
        }
    }
}
